﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;

namespace Kokomo.Controls
{
	public class DataGridRowIndexColumn : DataGridColumn
	{
		public DataGridRowIndexColumn()
		{
			this.Header = "#";
		}

		protected override System.Windows.FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
		{
			System.Collections.IList list = this.DataGridOwner.ItemsSource as System.Collections.IList;
			if (list != null)
			{
				int index = list.IndexOf(dataItem);
				if (index >= 0)
				{
					TextBlock textBlock = new TextBlock()
					{
						Text = (index + 1).ToString(),
						HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
						Background = Brushes.Silver
					};
					return textBlock;
				}
			}

			return null;
		}

		protected override System.Windows.FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
		{
			return null;
		}
	}
}
